package cn.hust.springboot.service.impl;

import cn.hust.springboot.bean.EmpExample;
import cn.hust.springboot.mapper.EmpMapper;
import cn.hust.springboot.service.IEmpService;
import cn.hust.springboot.bean.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements IEmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp getEmpById(Integer id) {
        return empMapper.selectByPrimaryKey(id);
    }

    @Override
    public Emp getEmpAndDeptById(Integer id) {
        return empMapper.getEmpAndDeptById(id);
    }

    @Override
    public List<Emp> selectReport(){
        return empMapper.selectReport();
    }
    @Override
    public List<Emp> getEmpAndDeptByDeptId(Integer id) {
        return empMapper.getEmpAndDeptByDeptId(id);
    }

    @Override
    public Emp getEmpByWorkID(Integer workID) {
        EmpExample example = new EmpExample();
        EmpExample.Criteria criteria = example.createCriteria();
        criteria.andWorkidEqualTo(workID.toString());
        return (Emp)this.empMapper.selectByExample(example);
    }

    @Override
    public List<Emp> getAllEmps() {
        EmpExample example = new EmpExample();
        EmpExample.Criteria criteria = example.createCriteria();
        criteria.andWorkstateEqualTo("在职");
        return this.empMapper.selectByExample(example);
    }

    @Override
    public List<Emp> getEmpAndDept() {
        return empMapper.getEmpAndDept();
    }

    @Override
    public List<Emp> getEmpAndDeptResigned() {
        return empMapper.getEmpAndDeptResigned();
    }

    @Override
    public int deleteEmpById(Integer id) {
        return empMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addEmp(Emp emp) {
        return empMapper.insert(emp);
    }

    @Override
    public int updateEmp(Emp emp) {
        return empMapper.updateByPrimaryKeySelective(emp);
    }

    @Override
    public List<Emp> query(String name) {
        return empMapper.query(name);
    }

    @Override
    public List<Emp> getEmpAndDeptByPosId(Integer id) {
        return empMapper.getEmpAndDeptByPosId(id);
    }

    @Override
    public List<Emp> getEmpAndDeptByDeptIdResigned(Integer id) {
        return empMapper.getEmpAndDeptByDeptIdResigned(id);
    }

    @Override
    public List<Emp> getEmpAndDeptByDeptIdNew(Integer id) {
        return empMapper.getEmpAndDeptByDeptIdNew(id);
    }
}
